package com.app17cos;

import java.util.ArrayList;
import java.util.List;

import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.assist.ImageLoadingListener;
import com.nostra13.universalimageloader.core.display.SimpleBitmapDisplayer;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;

public class DetailImgListBaseAdapter extends BaseAdapter {

	private ImageLoadingListener animateFirstListener = new Utility.AnimateFirstDisplayListener();
	private Context context = null;
	protected ImageLoader imageLoader = ImageLoader.getInstance();
	private List<String> list = new ArrayList<String>();
	DisplayImageOptions options;
	
	public DetailImgListBaseAdapter(Context context,List<String> list){
		this.context = context;
		this.list = list;
		options = new DisplayImageOptions.Builder()
		.showStubImage(R.drawable.ic_stub)
		.showImageForEmptyUri(R.drawable.ic_empty)
		.showImageOnFail(R.drawable.ic_error)
		.cacheInMemory()
		.cacheOnDisc()
		.displayer(new SimpleBitmapDisplayer())
		.build();
	}
	
	public Context getContext() {
		return this.context;
	}
	
	@Override
	public int getCount() {
		return list.size();
	}

	@Override
	public String getItem(int arg0) {
		return list.get(arg0);
	}

	@Override
	public long getItemId(int arg0) {
		return arg0;
	}

	@Override
	public View getView(int arg0, View arg1, ViewGroup arg2) {
		LinearLayout ll = null;
		if (arg1 != null) {
			ll = (LinearLayout) arg1;
		} else {
			ll = (LinearLayout) LayoutInflater.from(getContext()).inflate(
					R.layout.detail_img_listcell, null);
		}
		
		String imgurl = getItem(arg0);
		ImageView imgcos = (ImageView) ll.findViewById(R.id.detail_img);
		if (imgurl != null) {
			imageLoader.displayImage(imgurl, imgcos, options, animateFirstListener);
		}
		return ll;
	}

}
